package com.meizhuo.listview;

import android.content.Context;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;
import android.widget.SimpleAdapter;

import android.app.Fragment;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

public class MyFragment2 extends Fragment {

    int []arr = new int[]{
            R.drawable.pic1,
            R.drawable.pic2,
            R.drawable.pic3
    };

    String  [][]str = new String[][]{
            {"朋友圈"},
            {"扫一扫"},
            {"看一看"}
    };

    HashMap<String,Object> hashMap = new HashMap<>();

    private Context context ;

    public MyFragment2(){ }

    public  MyFragment2(Context context){
        this.context = context;
    }


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

        View view = inflater.inflate(R.layout.findlayout,container,false);

        // 具体的实现方法：
        List<HashMap<String,Object>> listData = new ArrayList();

        for(int i =0;i<str.length;i++){
            HashMap<String,Object> hashMap = new HashMap<>();
            hashMap.put("pic",arr[i]);
            hashMap.put("title",str[i][0]);
            listData.add(hashMap);
        }

        // 将 hashMap 的 key 组成一个字符串数组
        String[] form = new String[]{"pic","title"};
        // 将 item 布局中的 view 的 id 组成一个数组，要和 form 对应
        int[] to = new int[]{R.id.pic , R.id.title };
        SimpleAdapter simpleAdapter = new SimpleAdapter(context,listData,R.layout.find,form,to);

        ListView listView = view.findViewById(R.id.list_view);

        listView.setAdapter(simpleAdapter);

        return view;
    }
}
